package com.example;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * @Description: TODO
 * @Author: kangyang
 * @DateTime: 2024/10/23 16:28
 **/
public class Client {

    public static void main(String[] args) {
        int i = 0;
        while(i < 10000000) {
            new Thread(new ClientTestTask()).start();
        }
    }

    private static class ClientTestTask implements Runnable {

        @Override
        public void run() {
            Socket socket = new Socket();
            ObjectInputStream inputStream = null;
            ObjectOutputStream outputStream = null;
            try {
                socket.connect(new InetSocketAddress("127.0.0.1", 8888));
                System.out.println("Connect Server success!!");//连接服务器
                //实例化与服务端通信的输入输出流
                outputStream = new ObjectOutputStream(socket.getOutputStream());
//                inputStream = new ObjectInputStream(socket.getInputStream());
                System.out.println("Ready send message.....");
                outputStream.writeUTF("I am so cool, I am so handsome, so many girls love me!");
                outputStream.flush();

//                String s = inputStream.readUTF();
//                System.out.println(s);
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                try {
                    if (socket!=null) {
                        socket.close();
                    }
                    if (inputStream!=null) {
                        inputStream.close();
                    }
                    if (outputStream!=null) {
                        outputStream.close();
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }


}
